package com.bjc.config;

import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: spring-cloud-alibaba
 * @description: 授权规则配置
 * @author: bjc
 * @create: 2021-08-01 21:37
 */
//@Component
public class RequestOriginParserDefinition implements RequestOriginParser {

    /**
     * 定义区分来源：本质时通过request域获取到来源标识
     * app  pc
     * 然后交给流程应用位置进行匹配
     * @param request
     * @return
     */
    @Override
    public String parseOrigin(HttpServletRequest request) {
        String serviceName = request.getParameter("serviceName");
        if (StringUtils.isEmpty(serviceName)){
            throw new RuntimeException("serviceName 不能为空");
        }
        return serviceName;
    }
}
